import fetch, { BaseResponse, BaseSimpleResponse, loginUrl, RequestContentType } from './index'
import { AddressParam, StuAdd } from '@/types/address/userAdd'
import { XBusinesslineId } from '@/constants'

/**
 * 保存地址
 * @param param Partial<AddressParam>
 * @returns BaseResponse<any>
 */
export async function addressSave(param: Partial<AddressParam>): Promise<BaseResponse<any>> {
  const { data } = await fetch.post<BaseResponse<any>>(
    '/api/trade/PC/Address/Save/index',
    {
      'X-Businessline-Id': XBusinesslineId,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 删除地址
 * @param param Partial<AddressParam>
 * @returns BaseSimpleResponse<string>
 */
export async function addressDelete(
  param: Partial<AddressParam>,
): Promise<BaseSimpleResponse<string>> {
  const { data } = await fetch.post<BaseSimpleResponse<string>>(
    '/api/trade/PC/Address/Delete/index',
    {
      'X-Businessline-Id': XBusinesslineId,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 *地址列表信息
 * @param param Partial<AddressParam>
 * @returns BaseResponse<StuAdd[]>
 */
export async function addressLists(param: Partial<AddressParam>): Promise<BaseResponse<StuAdd[]>> {
  const { data } = await fetch.post<BaseResponse<StuAdd[]>>(
    '/api/trade/PC/Address/Lists/index',
    {
      'X-Businessline-Id': XBusinesslineId,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}
